﻿using B.S.BasicData.Api.Read.Application.Command.Account;
using B.S.BasicData.Api.Read.Application.Command.ADepartment;
using B.S.BasicData.Api.Read.Application.Command.Department;
using B.S.BasicData.Api.Read.Application.Command.Log;
using B.S.BasicData.Api.Read.Dtos;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Utils;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BasicData.Api.Read.Controllers
{
    /// <summary>
    /// 账号读控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class AccountController : ControllerBase
    {
        private readonly IMediator mediator;

        public AccountController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 查询所有用户分页的接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Task<ApiPaging<AccountDTO>> QueryAccount([FromQuery]QueryAccountCommand request)
        {
            return mediator.Send(request);
        }

     
        /// <summary>
        /// 登录接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Task<ApiResult<int>> Login([FromQuery]LoginAccountCommand request) {
            return mediator.Send(request);
        }


        [HttpGet]
        [AllowAnonymous]
        public Task<ApiResult<List<DepartmentTreeDTO>>> GetDepartmentTree([FromQuery]QueryDepartmentCommand request) {
            return mediator.Send(request);            
        }

        /// <summary>
        /// 查找部门树-接口
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Task<ApiResult<List<ADepartmentTreeDTO>>> GetDepartTree2([FromQuery]GetDepartmentCommand request) {
            return mediator.Send(request);
        }


        //[HttpGet]
        //public Task<String> GetMd6() {


        //    //DateTime.Now.get
        //    return Task.FromResult(DateTime.Now.ToString().GetMd6());
        //}
    }
}
